<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>管理员管理 - Layui</title>
<link rel="stylesheet" href="/layui/css/layui.css">
<link rel="stylesheet" href="/css/admin.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    @include('admin.header')
  </div>
  <div class="layui-side layui-bg-black">
    @include('admin.leftadmin')
  </div>
  <div class="layui-body">
   <form action="admin" method="post" style="margin-top: 20px">
   <div style="float:left">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">关键字</label>
        <div class="layui-input-inline">
          <input type="tel" name="k" lay-verify="shopname" autocomplete="off" class="layui-input shopname" value='<?php echo $k;?>'>
        </div>
      </div>
      <span style="width: 1070px;display: inline-block;"></span>
      <div class="layui-inline"><button class="layui-btn" lay-submit="" lay-filter="demo1">查询</button></div>
    </div>
    </div>
   </form>
   <div class="layui-inline"><button class="layui-btn" lay-submit="" lay-filter="demo1"><a href="/admin/admin/admin" style="color:white">重置</a></button></div>
  <div class="body_top" style="height:50px"></div>
  <table class="layui-table" lay-skin="line">
     <colgroup>
      <col width="150">
      <col width="250">
      <col width="250">
      <col width="200">
      <col width="200">
      <col width="250">
      <col width="300">
      <col>
     </colgroup>
     <thead>
      <tr>
        <th>ID</th>
        <th>账号</th>
        <th>密码</th>
        <th>权限</th>
        <th>说明</th>
        <th>添加时间</th>
        <th>操作</th>
      </tr> 
     </thead>
     <tbody>
     <?php foreach($users->results as $key=>$val):?>
      <tr>
        <td><?php echo $val['id']?></td>
        <td><?php echo $val['username']?></td>
        <td><?php echo $val['password']?></td>
        <td><?php echo $val['permission']?></td>
        <td><?php echo $val['explanation']?></td>
        <td><?php echo $val['addtime']?></td>
        <?php if($val['code']==0):?>
        <td>
       <!--  <a href="addoper?ad=<?php echo $val['username']; ?>"><button class="layui-btn layui-btn-small"><i class="layui-icon" style="color:white"></i></button></a>&nbsp&nbsp -->
        <button class="layui-btn layui-btn-small" id="add"><i class="layui-icon" style="color:white"></i></button></a>
        <!-- <a href="change?id=<?php echo $val['id']?>" style="color:white"><button class="layui-btn layui-btn-small"><i class="layui-icon"></i></button></a>&nbsp&nbsp --><button class="layui-btn layui-btn-small change"><i class="layui-icon"></i></button></a>
        <button class="layui-btn layui-btn-small"><i class="layui-icon" style="color:white"></i></button>

        </td>
        <?php else:?>
        <td>
        <a href="javascript:void(0)"><button class="layui-btn layui-btn-small"><i class="layui-icon" style="color:white"></i></button></a>&nbsp&nbsp&nbsp
      <!--   <a href="change?id=<?php echo $val['id']?>" style="color:white"><button class="layui-btn layui-btn-small"><i class="layui-icon"></i></button></a>&nbsp&nbsp --><button class="layui-btn layui-btn-small change"><i class="layui-icon"></i></button></a>
        <button class="layui-btn layui-btn-small dele"><i class="layui-icon" style="color:white"></i></button>
        </td>
        <?php endif;?>
      </tr>
      <?php endforeach;?>
     </tbody>
    </table> 
     <div id="page-v" style="margin-left: 50px"></div>  
     
  </div>
  <div class="layui-footer">
    <!-- 底部固定区域 -->
  </div>

</body>
</html>

<script src="/layui/layui.js"></script>
<script src="/js/jquery-1.10.1.min.js"></script>
<script>
layui.use('layer', function(){
    var layer = layui.layer;
    $(function(){
      $('.dele').click(function(){
      var id = $(this).parents('tr').find('td').eq(0).html();
      layer.confirm('确认删除?', function(index){
        $.ajax({
        url:'dele',
        type:'post',
        data:{'id':id},
        dataType:'json',
        success:function(d){
          if(d.code==200){
            layer.msg(d.msg, {
            icon: 1,
            time: 1000 //1秒关闭（如果不配置，默认是3秒）
          }, function(){
           window.location.reload();
          });  
          }else{
            layer.msg(d.msg);
          }
         }
        })
      layer.close(index);
   });    
  })
 })
});  

layui.use('element', function(){
  var element = layui.element(); //导航的hover效果、二级菜单等功能，需要依赖element模块
   
});

layui.use(['laypage', 'layer'], function(){
  var total = <?php echo $users->last; ?>;
  var laypage = layui.laypage
  ,layer = layui.layer;

  //好像很实用的样子，后端的同学再也不用写分页逻辑了。
  laypage({
    cont: 'page-v',
    pages:<?php echo $users->last; ?>, //可以叫服务端把总页数放在某一个隐藏域，再获取。假设我们获取到的是18
    curr: function(){ //通过url获取当前页，也可以同上（pages）方式获取
      var page = location.search.match(/page=(\d+)/);
      return page ? page[1] : 1;
    }(), 
    jump: function(e, first){ //触发分页后的回调
      if(!first){ //一定要加此判断，否则初始时会无限刷新
        location.href = '?page='+e.curr+'&k=<?php echo $k;?>';
      }
    }
  });
});


$('#add').on('click', function(){
  var addname = $(this).parents('tr').find('td').eq(1).html();
  layer.open({
  type: 2,
  title: addname,
  maxmin: true,
  shadeClose: true, //点击遮罩关闭层
  area : ['800px' , '520px'],
  content: 'addoper',
  end : function(){
    location.reload();
  }
  });
});

$('.change').on('click', function(){
  var pd = $(this).parents('tr').find('td').eq(0).html();
  layer.open({
  type: 2,
  title: "修改",
  maxmin: true,
  shadeClose: true, //点击遮罩关闭层
  area : ['800px' , '520px'],
  content: 'change?id='+pd,
  end : function(){
    location.reload();
  }

  });
});





</script>
